﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text.RegularExpressions;
using Enter.Common;
using Enter.Entity;
using Enter.BizLogic;


namespace Enter.Web.SystemAdmin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["code"] == null || Session["code"].ToString() == string.Empty || txtRndom.Text == null ||
           txtRndom.Text == string.Empty)
            {
                Session["code"] = null;
                Utils.ShowMessage("请输入随机码");
                return;
            }

            if (Session["code"].ToString() != txtRndom.Text)
            {
                Session["code"] = null;
                Utils.ShowMessage("随机码输入不正确");
                return;
            }

            Session["code"] = null;

            Sys_OperatorEntity sys_user = null;
            ResultPacket result = new ResultPacket();
            Sys_OperatorBLLSub.Login(txtLoginName.Text.Trim(), txtPass.Text.Trim(), ref sys_user);
            if (result.IsError)
            {
                Utils.ShowMessage(result.Description);
            }
            else
            {
                Session["LTR_AdminUsers"] = sys_user;

                string redirect_url = Request.QueryString["redirect_url"] ?? "";
                Regex re = new Regex(@"redirect_url=([a-zA-Z0-9_\/.&]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                Match m = re.Match(redirect_url);
                while (m.Success)
                {
                    redirect_url = m.Groups[1].ToString();
                    m = m.NextMatch();
                }
                redirect_url = redirect_url.ToLower().IndexOf("default.aspx") != -1 ? "" : redirect_url;

                Utils.GotoURL("default.aspx?redirect_url=" + redirect_url);
            }
        }
    }
}